package com.primus.server.entity.store;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.primus.server.entity.BaseEntity;
import com.primus.server.entity.location.Address;
import com.primus.server.entity.user.User;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;

@Entity
@Getter
@Setter
public class Store extends BaseEntity {

    private String name;

    private String code;

    private String phone;

    private String license;

    private String avatar;

    private Double score;

    private String description;

    @OneToOne
    private Address address;

    @OneToMany(fetch = FetchType.LAZY)
    @JsonIgnore
    private List<User> owners = Lists.newArrayList();

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Comment> comments = Lists.newArrayList();

    @OneToMany(mappedBy = "store", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Product> products = Lists.newArrayList();

}
